package com.sc.nft.controller;

import com.sc.nft.annotation.UserLogin;
import com.sc.nft.controller.request.IdRequest;
import com.sc.nft.entity.dto.TradingPoolCalculatePriceRatioRangeDTO;
import com.sc.nft.entity.dto.WhetherItCanBePaidDTO;
import com.sc.nft.entity.vo.*;
import com.sc.nft.pool.UserPool;
import com.sc.nft.service.TradingPoolConfigService;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/tradingPoolConfig")
@Api(tags = "交易池配置")
public class TradingPoolConfigController {
    private final TradingPoolConfigService tradingPoolConfigService;


    @ApiOperation(value = "获取交易池简单配置", notes = "获取交易池简单配置", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getTradingPoolEasyConfig", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public Result<TradingPoolEasyConfigVO> getTradingPoolEasyConfig(@RequestBody @Valid IdRequest idRequest) {
        return Result.success(tradingPoolConfigService.getTradingPoolEasyConfig(idRequest.getId()));
    }

    @ApiOperation(value = "交易池购买详情", notes = "交易池购买详情", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/tradingPoolPurchaseDetails", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public Result<TradingPoolPurchaseDetailsVO> tradingPoolPurchaseDetails(@RequestBody @Valid IdRequest idRequest) {
        if (!UserPool.getUser().getIsSm()) {
            return PageResult.fail("请先完成实名认证");
        }
        return Result.success(tradingPoolConfigService.tradingPoolPurchaseDetails(idRequest.getId()));
    }

    @ApiOperation(value = "交易池卖出详情", notes = "交易池卖出详情", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/tradingPoolSellDetails", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public Result<TradingPoolSellDetailsVO> tradingPoolSellDetails(@RequestBody @Valid IdRequest idRequest) {
        if (!UserPool.getUser().getIsSm()) {
            return PageResult.fail("请先完成实名认证");
        }
        return Result.success(tradingPoolConfigService.tradingPoolSellDetails(idRequest.getId(), UserPool.getUser()));
    }

    @ApiOperation(value = "获取交易池详情", notes = "获取交易池详情", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/getTradingPoolDetails", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public Result<TradingPoolDetailsVO> getTradingPoolDetails(@RequestBody @Valid IdRequest idRequest) {
        return Result.success(tradingPoolConfigService.getTradingPoolDetails(idRequest.getId()));
    }

    @ApiOperation(value = "计算价格范围", notes = "计算价格范围", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/calculatePriceRatioRange", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public Result<TradingPoolCalculatePriceRatioRangeVO> calculatePriceRatioRange(@RequestBody @Valid TradingPoolCalculatePriceRatioRangeDTO tradingPoolCalculatePriceRatioRangeDTO) {
        return Result.success(tradingPoolConfigService.calculatePriceRatioRange(tradingPoolCalculatePriceRatioRangeDTO));
    }

    @PostMapping(value = "/whetherItCanBePaid", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "是否可支付", notes = "是否可支付", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public Result<CurrentPriceVO> whetherItCanBePaid(@RequestBody WhetherItCanBePaidDTO dto) {
        return Result.success(tradingPoolConfigService.whetherItCanBePaid(dto));
    }
}
